(**********************************************************************

    :Program.  	 SuperLists.def
    :Contents.	 Text-list Playfield handler
    :Author.   	 Nicolas Benezan [bne]
    :Address.    Postwiesenstr. 2, D7000 Stuttgart 60
    :Phone.      711/333679
    :Copyright.  Public Domain (siehe ReadMe)
    :Language. 	 Modula-II
    :Translator. M2Amiga AMSoft
    :History.    V1.0b [bne] 28.05.88 (first PD-version Amok#2)
    :History.    V1.1a [bne] 10.06.88 (extended MemHandler)
    :History.	 + VAR AllocProc, DeallocProc
    :History.    V1.2b [bne] 20.07.88 ("FreeVert-only" also available)
    :History.	 + CONST first, last
    :History.    V1.3a [bne] 14.08.88 (+ MakeExtEntry, ClearList)
    
**********************************************************************)

DEFINITION MODULE SuperLists;

FROM Exec	IMPORT Node,List,NodePtr,Byte;
FROM Intuition	IMPORT GadgetPtr,WindowPtr,RequesterPtr;
FROM Graphics	IMPORT DrawModeSet,RastPortPtr;
FROM SYSTEM	IMPORT ADDRESS,BITSET;

CONST	oldList=FALSE;	(* RethinkList *)
	newList=TRUE;
        
        hideIt=TRUE;	(* InsertEntry, RemoveEntry *)
        showIt=FALSE;
        
        deallocIt=TRUE;	(* RemoveEntry *)
        letIt=FALSE;
        
        first=0;	(* InsertEntry, RemoveEntry *)
        last=-1;

TYPE	SuperListPtr=POINTER TO SuperList;
        EntryPtr=POINTER TO Entry;
        ExtEntryPtr=ADDRESS; (* POINTER TO RECORD MinEntry; UserData... END *)
        AnyEntryPtr=ADDRESS; (* EntryPtr or ExtEntryPtr *)
	SuperList=RECORD
	  list		:List;
          rastPort	:RastPortPtr;
          backPen	:INTEGER;
          propX,
          propY		:GadgetPtr;
          leftEdge,
          topEdge,
          width,
          height,
          FontXsize,
          FontYsize,
          FontBaseLine,
          dispRow,
          dispColumn,
          rows,
          columns	:INTEGER;
          topEntry,
          bottomEntry	:NodePtr;
          effWidth,
          effHeight	:INTEGER;
        END;
        MinEntry=RECORD
          node		:Node;
          frontPen,
          backPen	:Byte;
          drawMode	:DrawModeSet;
        END;
        Entry=RECORD
          node		:Node;
          frontPen,
          backPen	:Byte;
          drawMode	:DrawModeSet;
          userData	:LONGINT;
          userFlags	:BITSET;
        END;
        Directions=(Up,Down,Left,Right);
        AllocProcType=PROCEDURE(VAR ADDRESS,LONGINT);
        DeallocProcType=PROCEDURE(VAR ADDRESS);

VAR	AllocProc:AllocProcType;
	DeallocProc:DeallocProcType;

PROCEDURE RethinkList(List:SuperListPtr;New:BOOLEAN);
(*:Note.	See documentation for a complete description *)

PROCEDURE RefreshList(List:SuperListPtr);
(*:Input.	List: Pointer to a SuperList structure
  :Semantic.	Refreshes the display of the List *)

PROCEDURE RedrawEntry(List:SuperListPtr;Row:INTEGER);
(*:Input.	List: Pointer to a SuperList structure
  :Input.	Row: Number of the entry to be redrawn
  :Semantic.	Rewrites an entry on the display *)

PROCEDURE ScrollList(List:SuperListPtr;Dir:Directions);
(*:Input.	List: Pointer to a SuperList structure
  :Input.	Dir: The scrolling direction
  :Semantic.	Scrolls the list one character in the given direction
*)

PROCEDURE MakeEntry(text:ADDRESS;APen,BPen:INTEGER;
	Mode:DrawModeSet):EntryPtr;
(*:Input.	text: Pointer to a Text
  :Input.	APen,BPen: Foreground and background color
  :Input.	Mode: Draw mode, jam1 jam2 or complement
  :Semantic.	Allocates and initialises a new Entry structure *)

PROCEDURE MakeExtEntry(text:ADDRESS;APen,BPen:INTEGER;
	Mode:DrawModeSet;Size:CARDINAL):ExtEntryPtr;
(*:Input.	text: Pointer to a Text
  :Input.	APen,BPen: Foreground and background color
  :Input.	Mode: Draw mode, jam1 jam2 or complement
  :Input.	Size: Size of the complete entry structure
  :Input.	including the MinEntry RECORD
  :Semantic.	Allocates and initialises a new ExtEntry structure *)

PROCEDURE InsertEntry(List:SuperListPtr;entry:AnyEntryPtr;Row:INTEGER;
	hidden:BOOLEAN);
(*:Input.	List: Pointer to an initialised SuperList structure
  :Input.	entry: Pointer to the entry to be inserted
  :Input.	Row: At this position the new entry is inserted
  :Input.	hidden: TRUE: insertion is hidden FALSE: insertion
  :Input.	is displayed
  :Semantic.	Inserts a new entry into a SuperList *)

PROCEDURE RemoveEntry(List:SuperListPtr;Row:INTEGER;VAR mustRethink:
	BOOLEAN;hidden,Dealloc:BOOLEAN);
(*:Input.	List: Pointer to an initialised SuperList structure
  :Input.	Row: The entry with this number is removed
  :Input.	mustRethink: Result of a previous call to RemoveList()
  :Input.	or FALSE for the first call
  :Result.	mustRethink: TRUE: the removed entry was the longest
  :Result.	and RethinkList() must be called
  :Input.	hidden: TRUE: removal is hidden FALSE: removal
  :Input.	is displayed 
  :Input.	Dealloc: TRUE: entry will be deallocated
  :Note.	If this flag is set and the Entry was not created by
  :Note.	MakeEntry() or MakeExtEntry() the system might crash
  :Semantic.	Removes an entry out of a SuperList *)

PROCEDURE GetEntry(List:SuperListPtr;Row:INTEGER):AnyEntryPtr;
(*:Input.	List: Pointer to an initialised SuperList structure
  :Input.	Row: Number of the Entry to be searched
  :Result.	Pointer to the searched Entry or NIL if such
  :Result.	an Entry does not exist *)

PROCEDURE ClickRow(List:SuperListPtr;mouseX,mouseY:INTEGER):INTEGER;
(*:Input.	List: Pointer to an initialised SuperList structure
  :Input.	mouseX,mouseY: Mouse pointer coordinates relative to
  :Input.	the RastPort containing the SuperList.
  :Result.	Number of the clicked row or -1 if the Pointer was
  :Result.	out of the List's display area *)

PROCEDURE GetProp(List:SuperListPtr);
(*:Input.	List: Pointer to an initialised SuperList structure
  :Semantic.	Reads the proportional gadgets and sets the
  :Semantic.	List's internal values
  :Note.	Call RethinkList and RefreshList afer calling this *)

PROCEDURE SetProp(List:SuperListPtr;Window:WindowPtr;Requester:
	RequesterPtr);
(*:Input.	List: Pointer to an initialised SuperList structure
  :Input.	Window: Pointer to the window containing the SuperList
  :Input.	Requester: Pointer to the requester containing the
  :Input.	SuperList or NIL
  :Semantic.	Refreshes the SuperList's proportional gadgets *)

PROCEDURE ClearList(List:SuperListPtr;hidden:BOOLEAN);
(*:Input.	List: Pointer to an initialised SuperList structure
  :Input.	hidden: TRUE: clearing hidden FALSE: clear list and display
  :Semantic.	Removes and deallocates all entries of a SuperList
  :Note.	All entries must have been allocated by MakeEntry() or
  :Note.	MakeExtEntry(). Otherwise serious problems will arise ! *)

END SuperLists.
